package com.ruoyi.question.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.question.domain.DtQuestionAnalysis;
import com.ruoyi.question.service.IDtQuestionAnalysisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 答案解析Controller
 *
 * @author llc
 * @date 2025-01-06
 */
@RestController
@RequestMapping("/question/analysis")
public class DtQuestionAnalysisController extends BaseController {
    @Autowired
    private IDtQuestionAnalysisService dtQuestionAnalysisService;

    /**
     * 查询答案解析列表
     */
    @PreAuthorize("@ss.hasPermi('question:analysis:list')")
    @GetMapping("/list")
    public TableDataInfo list(DtQuestionAnalysis dtQuestionAnalysis) {
        startPage();
        List<DtQuestionAnalysis> list = dtQuestionAnalysisService.selectDtQuestionAnalysisList(dtQuestionAnalysis);
        return getDataTable(list);
    }

    /**
     * 导出答案解析列表
     */
    @PreAuthorize("@ss.hasPermi('question:analysis:export')")
    @Log(title = "答案解析", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DtQuestionAnalysis dtQuestionAnalysis) {
        List<DtQuestionAnalysis> list = dtQuestionAnalysisService.selectDtQuestionAnalysisList(dtQuestionAnalysis);
        ExcelUtil<DtQuestionAnalysis> util = new ExcelUtil<DtQuestionAnalysis>(DtQuestionAnalysis.class);
        util.exportExcel(response, list, "答案解析数据");
    }

    /**
     * 获取答案解析详细信息
     */
    @PreAuthorize("@ss.hasPermi('question:analysis:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(dtQuestionAnalysisService.selectDtQuestionAnalysisById(id));
    }

    /**
     * 新增答案解析
     */
    @PreAuthorize("@ss.hasPermi('question:analysis:add')")
    @Log(title = "答案解析", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DtQuestionAnalysis dtQuestionAnalysis) {
        return toAjax(dtQuestionAnalysisService.insertDtQuestionAnalysis(dtQuestionAnalysis));
    }

    /**
     * 修改答案解析
     */
    @PreAuthorize("@ss.hasPermi('question:analysis:edit')")
    @Log(title = "答案解析", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DtQuestionAnalysis dtQuestionAnalysis) {
        return toAjax(dtQuestionAnalysisService.updateDtQuestionAnalysis(dtQuestionAnalysis));
    }

    /**
     * 删除答案解析
     */
    @PreAuthorize("@ss.hasPermi('question:analysis:remove')")
    @Log(title = "答案解析", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(dtQuestionAnalysisService.deleteDtQuestionAnalysisByIds(ids));
    }
}
